// 该文件是用来放自定义 hooks 的地方
import { useState, useEffect } from 'react'

export function useBanner() {
    const [banner, setBanner] = useState([])

    useEffect(() => {
        fetch('http://121.89.205.189:3000/api/banner/list')
            .then(res => res.json())
            .then(res => {

                setBanner(res.data)
            })
    }, [])

    return banner
}


export function usePro(limitNum) {
    const [pro, setPro] = useState([])

    useEffect(() => {
        fetch('http://121.89.205.189:3000/api/pro/list?limitNum=' + limitNum)
            .then(res => res.json())
            .then(res => {
                setPro(res.data)
            })
    }, [])

    return pro.map(item => <li key={item.proid}>{item.proname}</li>)

}


export function useQueryId(eleid) {
    const [dom, setDom] = useState(null)
    useEffect(() => {
        setDom(document.getElementById(eleid))
    }, [eleid])
    return dom
}